<template>
    <div class="weixin_setting_dialog_container">
        <el-dialog :title="dialogOption.title" :visible.sync="dialogOption.visible"
                   v-dialogDrag width="600px">
            <div class="dialog_content">
                <setting-form :ref="settingFormRef" :type="code"
                              :account-set="row.sid" :rules="settingOption.rules" :label-width="labelWidth"
                              :fields="settingOption.fields" hide-submit />
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="handleCancel">取 消</el-button>
                <el-button type="primary" @click="saveOrUpdate()" v-btnLoading>确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>

import SettingForm from "../../common/SettingForm";
import setting from "#/setting";
export default {
    name: 'WeixinSettingDialog',
    components: { SettingForm },
    provide() {
        return {
            setChildrenRef: (name, ref) => {
                this[name] = ref;
            },
        };
    },
    data() {
        return {
            //弹窗option
            dialogOption: {
                visible: false,
            },
            row: {},
            code: undefined,
            settingOption: {},
            labelWidth:'160px',
        };
    },
    computed: {
        settingFormRef() {
            return `settingForm_${this.code}_${this.row ? this.row.sid : ''}`;
        },
    },
    methods: {
        async openDialog(row, options) {
            const _this = this;
            _this.row = row;
            _this.code = options.code;
            _this.settingOption = setting.wx_setting[options.type];
            _this.dialogOption = $.extend({}, _this.dialogOption, {
                title: options.title,
                visible: true,
            });
        },
        saveOrUpdate() {
            const _this = this;
            if (_this.$refs[_this.settingFormRef]) {
                _this.$refs[_this.settingFormRef].saveSetting().then(result => {
                    if (result) {
                        _this.handleCancel();
                    }
                });
            }
        },
        handleCancel() {
            this.dialogOption.visible = false
        },
    },
};
</script>
<style lang="less" rel="stylesheet/less">
.weixin_setting_dialog_container {
}
</style>
